﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace HA.Data
{
    public static class FlowVectorsAutoCompute
    {


        public static double ComputeLength(int xCellNum, int yCellNum, double xGridLength, double yGridLength)
        {
            //自动计算长度

            //解决方案：取单元格的平均X和平均Y，计算单元格对角线长度



            double gridXLength = xGridLength;
            double gridYLength = yGridLength;


            int xNum = xCellNum;
            int yNum = yCellNum;


            double xAverage = gridXLength / xNum;
            double yAverage = gridYLength / yNum;


            double length = Math.Sqrt(xAverage * xAverage + yAverage * yAverage);



            return length;

        }


        public static double ComputeScalingRatio(double range, double length)
        {
            //自动计算缩放比例

            //解决方案：所有单元格中向量的模的最大值max，最小值min的差值Range，向量定长度为length，则缩放比例scale=length / range;

            if (range < 0 || length < 0)
            {
                return 0;
            }


            double scaleRatio = length / range;


            return scaleRatio;

        }





    }
}
